package com.mccrea.principle.inversion;

/**
 * @Classname DependencyMethod
 * @Description 依赖关系传递方式
 * @Date 2021/5/6 0006 17:07
 * @Created by Mccrea_Gao
 */
public class DependencyMethod {
    public static void main(String[] args) {

    }
}

/**
 * 方式一通过接口传递依赖关系
 */
interface IOpenAndClose1 {
    void open(ITV itv);
}

interface ITV {
    void play();
}

class OpenAndClose1 implements IOpenAndClose1 {

    @Override
    public void open(ITV itv) {
        itv.play();
    }
}

/**
 * 通过构造方法传递依赖
 */
interface IOpenAndClose2 {
    void open();
}

class OpenAndClose2 implements IOpenAndClose2 {
    private ITV itv;

    public OpenAndClose2(ITV itv) {
        this.itv = itv;
    }

    @Override
    public void open() {
        itv.play();
    }
}

interface IOpenAndClose3 {
    void open();
    void setTv(ITV itv);
}

class OpenAndClose3 implements IOpenAndClose3 {

    private ITV itv;

    @Override
    public void open() {
        itv.play();
    }

    @Override
    public void setTv(ITV itv) {
        this.itv = itv;
    }
}
